<#assign className = table.className>
<#assign classNameLower = className?uncap_first>
package me.luger.project.manager.sys.controllers;

import me.luger.core.dao.nutz.entity.page.DataTableRequest;
import me.luger.core.mvc.controller.BaseController;
import me.luger.core.mvc.entity.Result;
import me.luger.core.mvc.interceptor.oplog.OpLog;
import org.nutz.lang.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import me.luger.project.${projectName}.modules.${moduleName}.service.${className}Service;
import me.luger.project.${projectName}.modules.${moduleName}.entity.${className};

import java.util.List;

/**
 * ${table.tableAlias} controller
 */
@Controller
@RequestMapping("/private/${moduleName}/${classNameLower}")
public class ${className}Controller extends BaseController {

    private String viewBasePath = "/admin/modules/${moduleName}/${classNameLower}/";

    @Autowired
    private ${className}Service ${classNameLower}Service;

    @RequestMapping(value = "",name = "${table.tableAlias}列表页面")
    public ModelAndView index(){
        return btlView(viewBasePath + "index");
    }

    @RequestMapping(value = "data",name = "获取${table.tableAlias}列表")
    @ResponseBody
    public Object data(@RequestBody final DataTableRequest dataTableRequest){
        return ${classNameLower}Service.data(dataTableRequest);
    }



    @RequestMapping(value = "delete",name = "删除${table.tableAlias}接口")
    @ResponseBody
    public Object delete(${table.pkColumn.simpleJavaType}[] ids){
        ${classNameLower}Service.delete(ids);
        return Result.success("delete success");
    }

    @RequestMapping(value = "/detail/{id}",name = "获取${table.tableAlias}详细信息接口")
    public ModelAndView detail(@PathVariable("id") ${table.pkColumn.simpleJavaType} id){
        ${className} ${classNameLower} = ${classNameLower}Service.getById(id);
        setAttr("${classNameLower}",${classNameLower});
        return btlView(viewBasePath + "detail");
    }

    @RequestMapping(value = "add",name = "添加${table.tableAlias}页面")
    public ModelAndView add(){
        return btlView(viewBasePath + "add");
    }

    @RequestMapping(value = "addDo",name = "添加${table.tableAlias}接口")
    @ResponseBody
    @OpLog(name = "添加${table.tableAlias}",msg = "添加${table.tableAlias}")
    public Object adddo(${className} ${classNameLower}){
        try{
            ${classNameLower} = ${classNameLower}Service.insert(${classNameLower});
        }catch (Exception e){
            return Result.error();
        }
        return Result.success();
    }

    @RequestMapping(value = "/edit/{id}",name = "更新${table.tableAlias}信息页面")
    public ModelAndView edit(@PathVariable ${table.pkColumn.simpleJavaType} id){
        ${className} ${classNameLower} = ${classNameLower}Service.getById(id);
        setAttr("${classNameLower}",${classNameLower});
        return btlView(viewBasePath + "edit");
    }

    @RequestMapping(value = "editDo",name = "更新${table.tableAlias}接口")
    @ResponseBody
    public Object editDo(${className} ${classNameLower}){
        try{
            ${classNameLower}Service.updateIgnoreNull(${classNameLower});
        }catch (Exception e){
            return Result.error();
        }
        return Result.success();
    }
}
